package DAO;

import connect.ConnectDB;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.Statement;
import java.util.Vector;

public class AccountDAO {

    public Connection conn;
    ResultSet rs = null;
    Statement st;
    PreparedStatement pst;
    public ConnectDB cdb;
    Vector<String> data;

    public AccountDAO() {
        cdb = new ConnectDB();
        cdb.getConnect();
        this.conn = cdb.conn;
    }

    public Vector loadDataUser(String username, String password) {
        try {
            String query = "SELECT "
                    + "             * "
                    + "     FROM "
                    + "             Account as A "
                    + "     JOIN "
                    + "             Employees as E "
                    + "     ON "
                    + "             A.EMPID = E.EMPID";
            st = conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_UPDATABLE);
            rs = st.executeQuery(query);
            
            data = new Vector<String>();
            
            while (rs.next()) {
                if (rs.getString("USERNAME").trim().equals(username)) {
                    if (rs.getString("PASSWORD").trim().equals(password)) {
                        data.add(rs.getString("EMPID"));
                        data.add(rs.getString("EMPNAME"));
                        data.add(rs.getString("USERNAME"));
                        data.add(rs.getString("PASSWORD"));
                        data.add(rs.getString("ACCESS"));
                        
                        return data;
                    }
                }
            }
            return data;
        } catch (Exception e) {
            System.out.println("Error in loadDataUser (AccountDAO): " + e.getMessage());
            return null;
        }
    }

    
}
